package diva.pap.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import diva.android_library.lang.ApplicationContext;

public class Settings {
  public static final String SHARED_PREFERENCES_KEY = "settings";
  public static final String SETTING_URL = "instalation_url";
  public static final String SETTING_USERNAME = "username";
  public static final String SETTING_PASSWORD = "password";
  private final SharedPreferences settings;

  public Settings() {
    settings =
        ApplicationContext.getContext().getSharedPreferences(SHARED_PREFERENCES_KEY,
            Context.MODE_PRIVATE);
  }

  public String getPassword() {
    return settings.getString(SETTING_PASSWORD, null);
  }

  public String getServerUrl() {
    return settings.getString(SETTING_URL, null);
  }

  public String getUsername() {
    return settings.getString(SETTING_USERNAME, null);
  }

  public void save(String url, String username, String password) {
    Editor editor = settings.edit();
    editor.putString(SETTING_URL, url);
    editor.putString(SETTING_USERNAME, username);
    editor.putString(SETTING_PASSWORD, password);
    editor.commit();
  }
}
